import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { InnerMenu } from '../models/inner-menu';
import { BaseService } from './base.service';

@Injectable({
  providedIn: 'root'
})
export class MenuService extends BaseService {
  menuSelectChange$ = new Subject<any>();
  menuUpdated$ = new Subject<InnerMenu>();

  // 查询页面列表
  queryPages(params: { name: string; viewId: string; type: string; pageIndex?: number; countOfPage?: number; }) {
    const url = 'api/page';
    return this.get(url, { params });
  }
  // 菜单列表
  queryMenus(params?: { orgId?: string; name?: string; pageIndex?: number; countOfPage?: number; }) {
    const url = 'api/menu';
    return this.get(url, { params });
  }
  // 菜单详情
  getMenuInfoById(id: string): Promise<InnerMenu> {
    const url = 'api/menu';
    return this.get(`${url}/${id}`);
  }
  // 删除菜单
  deleteMenu(id: string) {
    const url = 'api/menu';
    return this.delete(`${url}/${id}`);
  }
  // 添加菜单
  createMenu(menuInfo: InnerMenu) {
    const url = 'api/menu';
    return this.post(url, menuInfo);
  }
  // 编辑菜单
  updateMenu(menuInfo: InnerMenu): Promise<InnerMenu> {
    const url = 'api/menu';
    return this.put(url, menuInfo);
  }
}
